#! /bin/sh

set -e

package_name=bigmediaplayer

if [ -z "$package_name" ]; then
    print >&2 "Internal Error. Please report a bug."
    exit 1;
fi

case "$1" in
  install)
    dpkg-divert --package $package_name --divert /usr/share/applications/smplayer.desktop.distrib --rename /usr/share/applications/smplayer.desktop
    dpkg-divert --package $package_name --divert /usr/share/applications/smplayer_enqueue.desktop.distrib --rename /usr/share/applications/smplayer_enqueue.desktop
    dpkg-divert --package $package_name --divert /usr/share/applications/totem.desktop.distrib --rename /usr/share/applications/totem.desktop
    dpkg-divert --package $package_name --divert /usr/share/kde4/apps/solid/k9copy_assistant_open.desktop.distrib --rename /usr/share/kde4/apps/solid/actions/k9copy_assistant_open.desktop
    dpkg-divert --package $package_name --divert /usr/share/kde4/apps/solid/k9copy_open.desktop.distrib --rename /usr/share/kde4/apps/solid/actions/k9copy_open.desktop
    dpkg-divert --package $package_name --divert /usr/share/applications/kde4/k9copy_assistant.desktop.distrib --rename /usr/share/applications/kde4/k9copy_assistant.desktop
    dpkg-divert --package $package_name --divert /usr/share/applications/kde4/k9copy.desktop.distrib --rename /usr/share/applications/kde4/k9copy.desktop

;;

  upgrade)
        if [ "$(dpkg-divert --list /usr/share/applications/smplayer.desktop)" = "" ]
        then
	        dpkg-divert --package $package_name --divert /usr/share/applications/smplayer.desktop.distrib --rename /usr/share/applications/smplayer.desktop
	fi

        if [ "$(dpkg-divert --list /usr/share/applications/smplayer_enqueue.desktop)" = "" ]
        then
		dpkg-divert --package $package_name --divert /usr/share/applications/smplayer_enqueue.desktop.distrib --rename /usr/share/applications/smplayer_enqueue.desktop
	fi

        if [ "$(dpkg-divert --list /usr/share/applications/totem.desktop)" = "" ]
        then
		dpkg-divert --package $package_name --divert /usr/share/applications/totem.desktop.distrib --rename /usr/share/applications/totem.desktop
	fi

        if [ "$(dpkg-divert --list /usr/share/kde4/apps/solid/actions/k9copy_assistant_open.desktop)" = "" ]
        then
		dpkg-divert --package $package_name --divert /usr/share/kde4/apps/solid/k9copy_assistant_open.desktop.distrib --rename /usr/share/kde4/apps/solid/actions/k9copy_assistant_open.desktop
	fi
        if [ "$(dpkg-divert --list /usr/share/kde4/apps/solid/actions/k9copy_open.desktop)" = "" ]
        then
		dpkg-divert --package $package_name --divert /usr/share/kde4/apps/solid/k9copy_open.desktop.distrib --rename /usr/share/kde4/apps/solid/actions/k9copy_open.desktop
	fi
        if [ "$(dpkg-divert --list /usr/share/applications/kde4/k9copy_assistant.desktop)" = "" ]
        then
		dpkg-divert --package $package_name --divert /usr/share/applications/kde4/k9copy_assistant.desktop.distrib --rename /usr/share/applications/kde4/k9copy_assistant.desktop
	fi
        if [ "$(dpkg-divert --list /usr/share/applications/kde4/k9copy.desktop)" = "" ]
        then
		dpkg-divert --package $package_name --divert /usr/share/applications/kde4/k9copy.desktop.distrib --rename /usr/share/applications/kde4/k9copy.desktop
	fi




    ;;
  abort-upgrade)
    ;;
esac

exit 0
